package com.bardpub.controls 
{
	import com.greensock.easing.Back;
	import com.greensock.plugins.AutoAlphaPlugin;
	import com.greensock.plugins.TweenPlugin;
	import com.greensock.TweenLite;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	/**
	 * ...
	 * @author bardpub
	 */
	public class NavigationElement extends Sprite
	{
	
		private var _label:String;
		private var _pageName:String;
		private var _hitTestObject:Sprite;
		private var _bg:MovieClip;
		
	
		public function addItem(label:String, pageName:String):void 
		{
			
		}
		
		public function NavigationElement() 
		{
			TweenPlugin.activate([AutoAlphaPlugin]);
			_bg = getBg();
			addChild(_bg);
			_bg.width = 1;
			_bg.height = 25;
			_bg.visible = false;
		}
		
		override public function get width():Number { return _hitTestObject.width }
		
		override public function set width(value:Number):void 
		{
			super.width = value;
		}
		
		protected function getBg():MovieClip
		{
			var mc:MovieClip = new MovieClip();
			mc.graphics.beginFill(0,.6);
			mc.graphics.drawRect(-60, 0, 120, 200);
			mc.graphics.endFill();
			mc.x = 50;
			return mc;
		}
		
		protected function getLabelBmpd():BitmapData
		{
			var txt:TextField = new TextField();
			txt.autoSize = "left";
			txt.text = _label;
			
			var bitmapData:BitmapData = new BitmapData(txt.textWidth + 2, txt.textHeight + 2, true, 0);
			bitmapData.draw(txt);
			
			return bitmapData;
		}
		
		public function setStyle():void 
		{
			
			_hitTestObject = GetHitTestObject();
			addChild(_hitTestObject);
			
		}
		
		private function clickHandler(e:MouseEvent):void 
		{
			
		}
		
		public function GetHitTestObject():MovieClip
		{
			var mc:MovieClip = new MovieClip();
			mc.graphics.beginFill(0, .1);
			mc.graphics.drawRect(0, 0, 100, 25);
			mc.graphics.endFill();
			mc.buttonMode = mc.useHandCursor = true;
			mc.addEventListener(MouseEvent.CLICK, clickHandler);
			mc.addEventListener(MouseEvent.ROLL_OVER, overHandler);
			this.addEventListener(MouseEvent.ROLL_OUT, outHandler);
			mc.addEventListener(MouseEvent.MOUSE_DOWN, downHandler);
			mc.addEventListener(MouseEvent.MOUSE_UP, upHandler);
			return mc;
			
		}
		
		private function upHandler(e:MouseEvent):void 
		{
			
		}
		
		private function downHandler(e:MouseEvent):void 
		{
			
		}
		
		private function outHandler(e:MouseEvent):void 
		{
			TweenLite.to(_bg, .5, { autoAlpha:0 ,  width:1, ease:Back.easeOut} );
		}
		
		private function overHandler(e:MouseEvent):void 
		{
			
			TweenLite.to(_bg, .6, { autoAlpha:1 ,  width:120, ease:Back.easeOut} );
		}
		

		public function get label():String { return _label; }
		
		public function set label(value:String):void 
		{
			_label = value;
			setStyle();
		}
		
		public function get pageName():String { return _pageName; }
		
		public function set pageName(value:String):void 
		{
			_pageName = value;
		}
		
		
	
		
	}

}